<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <link rel="icon" type="image/x-icon" href="/zf/images/favicon.ico">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>注册|房屋租赁系统</title>
    <link rel="stylesheet" type="text/css" href="/zf/css/styles1.css">
    <link rel="stylesheet" type="text/css" href="/zf/css/base.css" />
</head>
<body>
<div class="wrapper">
    <div class="container">
        <h1>房屋租赁系统</h1>
        <form class="form" id="regiserform">
            <div><input type="text" id="username" name="username" placeholder="用户名"></div>
            <div><input type="password" id="password" name="password" placeholder="密码"></div>
            <div><input type="text" id="mail" name="mail" placeholder="邮箱"></div>
            <div class="emailcode clearfix">
                <input type="text" id="code" name="code" placeholder="验证码">
                <button type="button" onclick="sendCode()" id="getemailcode-btn">获取验证码</button>
            </div>
            <button type="button" onclick="regUser()" id="register-button">管理员注册</button>
        </form>
    </div>

    <ul class="bg-bubbles">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>

</div>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
    // 获取验证码
    function getcode() {
        var getCode = document.getElementById('getemailcode-btn');
        var wait = 60;
        function time(getCode) {
            if (wait === 0) {
                getCode.removeAttribute("disabled");
                getCode.innerHTML = "获取验证码";
                wait = 60;
            } else {
                getCode.setAttribute("disabled", true);
                getCode.innerHTML = wait + "秒后重试";
                wait--;
                setTimeout(function() {
                    time(getCode);
                }, 1000);
            }
        }
        time(getCode);
    }



    function sendCode(){
        getcode();
        $.ajax({
            type:'POST',
            url:'sendMail',
            data:{
                'to':$("#mail").val(),
                'username':$("#username").val()
            },
            dataType:"json",
            crossDomain:true,
            async:false,
            cache:false,
            success:function(data){
                alert(data.msg);
            },
            error:function(data){
            }
        });
    }

    //注册验证
    function regUser(){
        $.ajax({
            type:'POST',
            dataType:"json",/* 返回的字符串用text，返回的json对象用json */
            url:'registercheck',
            data:$("#regiserform").serialize(),
            crossDomain:true,
            async:false,
            cache:false,
            success:function(data){
                alert(data.msg);
                if(data.code === 1){
                    window.location.href = "login"
                }
            },
            error:function(data){

            }
        })
    }
</script>
</body>

</html>